#include "config.h"
#include <stdio.h>
#include "params/params_inc.h"

INT16 buff1[4704]; 
INT16 buff2[4704];
INT16 fc3_dout[10];


int lenet5_forward(INT16 *img_in)
{
    /* code */
    lenet_c1(
        (INT16 (*)[32][32])     img_in,
        (INT16 (*)[1][5][5])    c1_weight, 
        (INT16 (*))             c1_bias,
        (INT16 (*)[28][28])     buff1);
    lenet_mp1(
        (INT16 (*)[28][28])buff1,
        (INT16 (*)[14][14])buff2);
    lenet_c2(
        (INT16 (*)[14][14])     buff2,
        (INT16 (*)[6][5][5])    c2_weight,
        (INT16 (*))             c2_bias,
        (INT16 (*)[10][10])     buff1);
    lenet_mp2(
        (INT16 (*)[10][10])buff1,
        (INT16 (*)[5][5])buff2);
    lenet_fc1(
        (INT16 (*))buff2,
        (INT16 (*))buff1,
        (INT16 (*)[400])fc1_weight,
        (INT16 (*))fc1_bias);
    lenet_fc2(
        (INT16 (*))buff1,
        (INT16 (*))buff2,
        (INT16 (*)[120])fc2_weight,
        (INT16 (*))fc2_bias);
    lenet_fc3(
        (INT16 (*))buff2,
        (INT16 (*))fc3_dout,
        (INT16 (*)[84])fc3_weight,
        (INT16 (*))fc3_bias);

    int arg_max = 0;
    INT16 max_val = 0;
    for (int i = 0; i < 10; i++){
        if (max_val < fc3_dout[i]){
            max_val = fc3_dout[i];
            arg_max = i;
        }
        // printf("%d\n", fc3_dout[i]);
    }
    // printf("arg max = %d\n", arg_max);
    return arg_max;
}

int main(int argc, char const *argv[])
{
    /* code */
    int result = 0;
    result =lenet5_forward((INT16 (*))img_in_0); printf("%d / %d\n", 0, result);
    result =lenet5_forward((INT16 (*))img_in_1); printf("%d / %d\n", 1, result);
    result =lenet5_forward((INT16 (*))img_in_2); printf("%d / %d\n", 2, result);
    result =lenet5_forward((INT16 (*))img_in_3); printf("%d / %d\n", 3, result);
    result =lenet5_forward((INT16 (*))img_in_4); printf("%d / %d\n", 4, result);
    result =lenet5_forward((INT16 (*))img_in_5); printf("%d / %d\n", 5, result);
    result =lenet5_forward((INT16 (*))img_in_6); printf("%d / %d\n", 6, result);
    result =lenet5_forward((INT16 (*))img_in_7); printf("%d / %d\n", 7, result);
    result =lenet5_forward((INT16 (*))img_in_8); printf("%d / %d\n", 8, result);
    result =lenet5_forward((INT16 (*))img_in_9); printf("%d / %d\n", 9, result);
    return 0;
}
